﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using iBuproModel;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using iBuproModel.Repositories.Classes;
using System.Collections;
using IBupro.Models.Classes;
using iBuproModel.Repositories;
using iBuproModel.Repositories.Interfaces;

namespace IBupro.Models
{
    public class StudentModel : CustomModel
    {
        [Required(ErrorMessage="Specify first name")]
        public string FirstName { get; set; }

        [Required(ErrorMessage = "Specify last name")]
        public string LastName { get; set; }

        [Required(ErrorMessage = "Specify email")]
        public string Email {get;set;}

        public int StudentField { get; set; }


        public string OldPassword { get; set; }

        public string NewPassword { get; set; }

        public string ConfirmPassword { get; set; }

        public StudentModel()
        {
        }

        public StudentModel(User user)
        {
            this.FirstName = user.FirstName;
            this.LastName = user.LastName;
            this.Email = user.Email;

            if (user.StudentField != null)
                this.StudentField = user.StudentField.Id;

        }

        public SelectList GetStudentFieldSelectList()
        {
            return GetStudentFieldSelectList(null);
        }


        public SelectList GetStudentFieldSelectList(int? selectedValue)
        {
            IStudentFieldRepository repository = repositoryService.StudentFieldRepositoryCreateInstance();

            var list = from p in repository.GetAll().ToList()
                       select new SelectListItem
                       {
                           Selected = false,
                           Text = p.Shortcut + " " + p.Name,
                           Value = p.Id.ToString()
                       };

            return new SelectList(list,"Value","Text", selectedValue);
        }
    }


}